package com.o2o.cleaning.month.platform.ebusiness_plat.jumei_2019_7.Jumei_utils

import org.apache.spark.sql.SparkSession
import com.o2o.cleaning.month.platform.ebusiness_plat.jumei_2019_7.JuMei
//import platform.jumei.jumei_th1.JuMei

object brand_util {


  def brand_add_util (data_path:String,spark:SparkSession) = {
    val platform = "jumei"
    val month = JuMei.month
    val sourcedatas = spark.read.json(data_path)
      .select("platformName", "brandValueId", "brandName", "firstCategoryId")
    sourcedatas.registerTempTable("sourcedata")
    //品牌表
    val brandtable = spark.read.json(s"s3a://private/private_han/brandtableresult20181111/${platform}/*")
    brandtable.registerTempTable("brandtable")
    val brandadd = spark.sql(
      """
        |select
        |concat(t1.brandValueId,"|",t1.firstCategoryId) brandCcId,
        |t1.platformName,
        |t1.brandValueId,
        |t1.brandName,
        |t1.firstCategoryId
        |from
        |sourcedata t1
        |left join
        |brandtable t2
        |on t1.brandValueId = t2.brandValueId
        |where t2.brandValueId is null
      """.stripMargin).dropDuplicates("brandCcId")
    println(s"${platform} :" + brandadd.count())
    brandadd.repartition(1).write.json(s"s3a://private/private_han/brandtableaddres/${month}/${platform}")

  }


}
